package net.tv90.volunteerserveradmin.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckRole;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import net.tv90.volunteerserveradmin.annotation.OptLogger;
import net.tv90.volunteerserveradmin.constant.OptLoggerConstant;
import net.tv90.volunteerserveradmin.constant.RoleConstant;
import net.tv90.volunteerserveradmin.model.domain.GradeSubmission;
import net.tv90.volunteerserveradmin.model.dto.GradeSubmissionDTO;
import net.tv90.volunteerserveradmin.model.vo.GradeVO;
import net.tv90.volunteerserveradmin.service.GradeSubmissionService;
import net.tv90.volunteerserveradmin.utils.entity.Result;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Validated
@CrossOrigin
@RestController
@RequestMapping("grade")
@Tag(name = "教师管理成绩接口")
public class GradeController {

    @Resource
    private GradeSubmissionService gradeSubmissionService;

    @PostMapping("/grade-student/{teacherId}/{studentId}/{projectId}")
    @OptLogger(OptLoggerConstant.ADD)
    @SaCheckRole(RoleConstant.TEACHER)
    @Operation(summary = "给学生评分", description = "教师给参加志愿者项目的学生评分")
    public Result<Void> gradeStudent(@PathVariable Long teacherId, @PathVariable Long studentId, @PathVariable Long projectId, @RequestBody GradeSubmissionDTO gradeSubmissionDTO) {
        gradeSubmissionService.submitGrade(teacherId, studentId, projectId, gradeSubmissionDTO);
        return Result.success();
    }

//    @GetMapping("/{teacherId}/{projectId}")
//    @OptLogger(OptLoggerConstant.QUERY)
//    @SaCheckRole(RoleConstant.TEACHER)
//    @Operation(summary = "查看项目评分", description = "查看某个项目下所有学生的评分")
//    public Result<List<GradeSubmission>> getGrades(@PathVariable Long teacherId, @PathVariable Long projectId) {
//        return Result.success(gradeSubmissionService.getGradesForProject(teacherId, projectId));
//    }

    @GetMapping("/query-student-grade/{studentId}/{projectId}")
    @OptLogger(OptLoggerConstant.QUERY)
    @SaCheckLogin
    @Operation(summary = "查看学生某项目评分", description = "根据学生id和志愿活动Id查看某个项目下学生的评分")
    public Result<GradeVO> queryStudentGrade(@PathVariable Long studentId, @PathVariable Long projectId) {
        return Result.success(gradeSubmissionService.queryStudentGrade(studentId, projectId));
    }

}
